 package com.dragon.loan.repository;

 import com.dragon.common.entity.search.Searchable;
 import com.dragon.common.repository.mybatis.BaseRepository;
 import com.dragon.common.repository.mybatis.paginator.domain.PageBounds;
 import com.dragon.loan.entity.AcLoanApplyInfo;
 import com.dragon.loan.entity.AcLoanApplyInfoAddress;
 import com.dragon.loan.entity.McamAcLoanApplyImageInfo;
 import com.dragon.loan.vo.loanSuccessDto;
 import com.dragon.util.Criteria;
 import com.fintech.common.entity.ChannelCerformanceDto;
 import org.apache.ibatis.annotations.Param;

 import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;

public interface AcLoanApplyInfoRepository extends BaseRepository<AcLoanApplyInfo, Long>{
	
	public List<McamAcLoanApplyImageInfo> selectAttachmentInfo(String caseId);

	public int updateByLoanId(AcLoanApplyInfo acLoanApplyInfo);
	
	public AcLoanApplyInfo findByLoanId(String loanId);
	
	public AcLoanApplyInfo queryHisCarInsuranceLoanInfo(String custIdCard);
	
	public AcLoanApplyInfo queryHisLoanInfo(@Param("custIdCard") String custIdCard,@Param("productType") long productType);
	
	public List<Map<String,Object>> selectLoanStatusInfo(Searchable searchable, PageBounds pagebounds);
	
	public List<Map<String,Object>> selectLoanStatusNotInInfo(Map<String,Object> map, PageBounds pagebounds);
	
	public List<Map<String,Object>> queryLoanStatusInfo(Criteria<AcLoanApplyInfo> param );
	
	public List<Map<String,Object>> selectLoanInfList(Map<String,Object> map, PageBounds pagebound);

	public Map<String,Object> selectRankByLoanMoneyAct(Map<String,Object> map);
	
	public Long selectOrderNum(Map<String,Object> map);
	
	public Long selectOrderNumByUserIdList(Map<String,Object> map);
	
	public Map<String,Object> selectTotalLoanMoenyAndCount(Map<String,Object> map);
	
	public Long selectOverdueCount(Map<String,Object> map);
	
	/**
	 * 查询放款金额
	 * @param searchable
	 * @return
	 */
	public BigDecimal selectLoanAmt(Searchable searchable);
	
	/**
	 * 查询按进件笔数的排名
	 * @param map
	 * @return
	 */
	public Long selectRankByOrderNum(Map<String,Object> map);
	
	/**
	 * 查询按放款金额的排名
	 * @param map
	 * @return
	 */
	public Long selectRankByLoanAmt(Map<String,Object> map);
	
	/**
	 * 查询按放款笔数的排名
	 * @param map
	 * @return
	 */
	public Long selectRankByLoanNum(Map<String,Object> map);
	
	/**
	 * 查询客户经理当前逾期的总金额
	 * @param userId
	 * @return
	 */
	public BigDecimal selectOverdueAmt(String userId);
	
	/**
	 * 查询客户经理的历史放款金额和当前逾期的总金额
	 * @param map
	 * @return
	 */
	public List<Map<String,Object>> selectLoanAmtAndOverdueAmt(Map<String,Object> map);
	
	public Long selectNeedRepaymentCount(Map<String,Object> map);
	
	public List<Map<String,Object>> selectNeedRepaymentCust(Map<String,Object> map, PageBounds pagebounds);
	
	public List<Map<String,Object>> selectOverdueCust(Map<String,Object> map, PageBounds pagebounds);
	
	/**
	 * 查询客户经理所属渠道的所有用户
	 * @param userId
	 * @return
	 */
	public List<String> selectUserIdListInChannel(String userId);
	
	/**
	 * 查询客户经理所在机构级别
	 * @param userId
	 * @return
	 */
	public Integer selectUserOrgLevel(String userId);

	/**
	 * 查询客户经理所属门店的所有用户
	 * @param userId
	 * @return
	 */
	List<String> selectUserIdListInShop(String userId);
	
	/**
	 * 查询客户经理所属团队的所有用户
	 * @param userId
	 * @return
	 */
	public List<String> selectUserIdListInTeam(String userId);
	
	public Long selectUserCountOfPosition(String positionId);
	
	/**
	 * 查询团队长下客户经理待申请放款记录
	 * @param map
	 * @param pagebounds
	 * @return
	 */
	public List<Map<String,Object>> queryApplyReleaseMoneyList(Map<String,Object> map, PageBounds pagebounds);
	
	/**
	 * 查询申请待放款的详细详细
	 * @param loanId
	 * @return
	 */
	public Map<String,Object> queryApplyReleaseMoneyDetail(String loanId);
	
	/**
	 * 查询客户正在贷款申请中的记录条数
	 * @param custIdCard
	 * @return
	 */
	public Long selectCustApplyingCount(String custIdCard);
	
    public Long selectUserCountInChannel(String userId);

	public Long selectUserCountInShop(String userId);
	
	public Long selectUserCountInTeam(String userId);
	
	public Map<String,Object> selectAppIdAndCaseId(String loanId);
	
	public BigDecimal selectPrincipalAmtAct(String loanId);
	
	public int updateCreditResult(Map<String,Object> map);
	
	public List<Map<String,Object>> queryLoanByCustInfo(Map<String,Object> map);
	
	public List<AcLoanApplyInfo> queryByAcLoanApplyBxInfo(AcLoanApplyInfo acLoanApplyBxInfo);
	
	
	/**
	 * 根据loandid查询借据
	 * @param loanid
	 * @return
	 */
	public Map<String,Object> queryDebt(String loanid);
	
	public Map<String,Object> selectManagerInfo(String userId);
	
	public Map<String,Object> selectTeamLeaderInfo(String userId);
	
	public Map<String,Object> selectShopLeaderInfo(String userId);
	
	public String selectChannelLeaderByChannelId(String channelId);

	public List<Map<String,String>> queryByCustIDCard(String custIDCard);

	AcLoanApplyInfo queryPlanLoanInfo(String userId);
	//查询已签协议
	public List<Map<String, Object>> queryByCustIdCardAndType(
			Map<String, Object> dataMap);

	public AcLoanApplyInfo queryIDCardByMobileNum(String mobileNum);
	/**
	 * 借款记录
	 * @param userInfo
	 * @return
	 */
	public List<Map<String,String>> borrowList(String userInfo);
	
	/**
	 * 客户删除借款记录
	 * @param id
	 * @return
	 */
	public int deleteborrowList(Integer id);

	public int blackListVerify(String identityCard);
	
	/**
	 * 查询进行中的状态
	 * @param identityCard
	 * @return
	 */
	public String selectCustApplyingStatus(String identityCard);
	/**
	 * 查询进行中的状态
	 * @param identityCard
	 * @return
	 */
	public String selectCustApplyingLoanId(String identityCard);
	
	/**
	 * 查询进行中的状态
	 * @param identityCard
	 * @return
	 */
	public List<Map<String, String>> selectCustApplyingStatus2(@Param("identityCard") String identityCard, @Param("classify") String classify);
	
	AcLoanApplyInfo selectLastLoanInfo(String custIdCard);

	public List<String> selectUserIdListByChannel(String userId);
	
	/**
	 * 查询申请和自然时间的进件数
	 * @param userIds
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	Integer queryPerformanceIntoCount(@Param("userIds") List<Integer> userIds
			,@Param("startDate") Date startDate,@Param("endDate") Date endDate);
	
	/**
	 * 查询申请时间的通过数
	 * @param userIds
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	Integer queryApplayLoanPassCount(@Param("userIds") List<Integer> userIds
			,@Param("startDate") Date startDate,@Param("endDate") Date endDate);
	/**
	 * 查询申请时间的放款数
	 * @param userIds
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	Integer queryApplayLoanCount(@Param("userIds") List<Integer> userIds
			,@Param("startDate") Date startDate,@Param("endDate") Date endDate);
	/**
	 * 查询申请时间的放款额
	 * @param userIds
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	Double queryApplayLoanMoney(@Param("userIds") List<Integer> userIds
			,@Param("startDate") Date startDate,@Param("endDate") Date endDate);
	
	
	
	
	/**
	 * 查询自然时间的通过数
	 * @param userIds
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	Integer queryNaturePassCount(@Param("userIds") List<Integer> userIds
			,@Param("startDate") Date startDate,@Param("endDate") Date endDate);
	/**
	 * 查询自然时间的放款数
	 * @param userIds
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	Integer queryNatureLoanCount(@Param("userIds") List<Integer> userIds
			,@Param("startDate") Date startDate,@Param("endDate") Date endDate);
	/**
	 * 查询自然时间的放款额
	 * @param userIds
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	Double queryNatureLoanMoney(@Param("userIds") List<Integer> userIds
			,@Param("startDate") Date startDate,@Param("endDate") Date endDate);
	
	/**
	 * 渠道业绩查询
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	//List<Map<String,Object>> queryChannelPerformance(ChannelCerformanceDto channelCerformanceDto);
	
	/**
	 * 客户经理业绩查询(申请时间)
	 * @param channelCerformanceDto
	 * @return
	 */
	List<Map<String,Object>> queryChannelPerformanceKehujingliS(ChannelCerformanceDto channelCerformanceDto);
	/**
	 * 团队业绩查询(申请时间)
	 * @param channelCerformanceDto
	 * @return
	 */
	List<Map<String,Object>> queryChannelPerformanceTuanduiS(ChannelCerformanceDto channelCerformanceDto);
	/**
	 * 二级渠道业绩查询(申请时间)
	 * @param channelCerformanceDto
	 * @return
	 */
	List<Map<String,Object>> queryChannelPerformanceEejiS(ChannelCerformanceDto channelCerformanceDto);
	
	/**
	 * 一级渠道业绩查询(申请时间)
	 * @param channelCerformanceDto
	 * @return
	 */
	List<Map<String,Object>> queryChannelPerformanceYijiS(ChannelCerformanceDto channelCerformanceDto);
	
	
	/**
	 * 客户经理业绩查询(自然时间)
	 * @param channelCerformanceDto
	 * @return
	 */
	List<Map<String,Object>> queryChannelPerformanceKehujingliZ(ChannelCerformanceDto channelCerformanceDto);
	/**
	 * 团队业绩查询(自然时间)
	 * @param channelCerformanceDto
	 * @return
	 */
	List<Map<String,Object>> queryChannelPerformanceTuanduiZ(ChannelCerformanceDto channelCerformanceDto);
	
	/**
	 * 二级渠道业绩查询(自然时间)
	 * @param channelCerformanceDto
	 * @return
	 */
	List<Map<String,Object>> queryChannelPerformanceEejiZ(ChannelCerformanceDto channelCerformanceDto);
	/**
	 * 一级渠道业绩查询(自然时间)
	 * @param channelCerformanceDto
	 * @return
	 */
	List<Map<String,Object>> queryChannelPerformanceYijiZ(ChannelCerformanceDto channelCerformanceDto);
	
	/**
	 * ##查询客户经理自己的业绩(自然时间)
	 */
	List<Map<String,Object>> queryChannelPerformanceSelf(ChannelCerformanceDto channelCerformanceDto);
	
	/**
	 * 根据产品id来获取对应的模板号
	 * @param productId
	 * @return
	 */
	public List<Map<String, Object>> selectProtocolTemplateByProductId(Map<String, Object> map);
	
	public List<Map<String, Object>> selectProtocolTemplateByFundId(Map<String, Object> map);
	
	
	/**
	 * 根据用户身份证号获取这个用户之前的客户经理的ID 目前适用于线下产品（云房贷 云展业）
	 * @param paramMap
	 * @return
	 */
	public Integer getCustomerManagerByCustomerIdentityCard(Map<String, Object> paramMap);
	
	/**
	 * 针对同一款产品：如果客户在Y天内被系统拒绝过一次的，同一客户再次申请，拒绝客户申请
	 * @param paramMap
	 * @return
	 */
	public String isPassBySameCustomersApplySameProduct(Map<String, Object> paramMap);

	
	void updateByFundSource(Map<String, Object> paramMap);
	
	String selectFundSourceByLoanId(String loanId);
	
	Map<String, Object> selectCountBycustomerIdentityCardAndStatus(String customerIdentityCard);
	
	AcLoanApplyInfo selectByCustomerIdentityCard(String customerIdentityCard);
	
	Map<String, Object> selectCustApplyingProductName(String custIdCard);

	BigDecimal getCommissionSumByMobileNum(String mobileNum);

	public List<Map<String, Object>> selectSubBankByAreaAndBankCode(Map<Object, Object> resultMap);

	public String selectHeadBankByCityNo(Map<String, Object> paramMap);
	
	public int insertFake(Map<String, Object> paramMap);

	public Map<String, Object> getDecisionLimitMap(String loanId);
	
	public Map<String,Object> queryByLoanId(String loanId);
	
	AcLoanApplyInfo selectLastLoanInfoYzy(String identityCard);
	
	public Map<String, Object> getLoanAfterInfo(Map<String,Object> map);
	
	
	/**
	 * 根据机构code统计旗下的业绩
	 * @param param
	 * @return
	 */
	Integer selectLoanStatusOrgCode(Map<String,Object> param);
	/**
	 * userid查询业绩
	 * @param param
	 * @return
	 */
	Integer selectLoanStatusUserId(Map<String,Object> param);
	
	/**
	 * 区域用户统计
	 * @param param
	 * @return
	 */
	Integer regionEmployeeStatusTotal(Map<String,Object> param);
	
	/**
	 * 区域用户统计（优化性能）
	 * @param param
	 * @return
	 */
	Integer regionEmployeeStatusTotal2(Map<String,Object> param);
	
	/**
	 * 根据状态查询该状态拥有的机构(可用于查询一，二，团队机构时使用)
	 * @param param
	 * @return
	 */
	List<Map<String,Object>> queryOrgByStatus(Map<String,Object> param);
	
	/**
	 * 根据团队长姓名搜索团队机构
	 * @param param
	 * @return
	 */
	List<Map<String,Object>> seachOrgByTuanName(Map<String,Object> param);
	
	/**
	 * 根据状态查询该状态拥有的二级机构(区域员工专用)
	 * @param param
	 * @return
	 */
	List<Map<String,Object>> queryRegionEmployeeStatusOrg(Map<String,Object> param);
	
	/**
	 * 根据团队长名称搜索团队
	 * @param param
	 * @return
	 */
	List<Map<String,Object>> seachRegionTuanByName(Map<String,Object> param);
	
	/**
	 * 根据状态查询该状态拥有的客户经理(用于团队长查询客户经理)
	 * @param param
	 * @return
	 */
	List<Map<String,Object>> queryEmployeeByStatus(Map<String,Object> param);
	
	
	
	/**
	 * 根据状态查询该状态拥有的客户(用于客户经理查询客户)
	 * @param param
	 * @return
	 */
	List<Map<String,Object>> queryClientByStatus(Map<String,Object> param);
	
	/**
	 * 根据状态查询该状态拥有的客户(区域员工专用)
	 * @param param
	 * @return
	 */
	List<Map<String,Object>> queryRegionEmployeeClientByStatus(Map<String,Object> param);
	
	/**
	 * 根据状态查询该状态拥有的客户(机构负责人专用)
	 * @param param
	 * @return
	 */
	List<Map<String,Object>> orgQueryClientByStatus(Map<String,Object> param);
	
	/**
	 * 查询机构下指定状态的进件详情
	 * @param param
	 * @return
	 */
	List<Map<String,Object>> queryOrgClientByStatus(Map<String,Object> param);
	
	public void insertCmApp(Map<String,Object> map);

	/**
	 * 查看已经结清的数量
	 * 
	 * @param idNo
	 * @return
	 */
	public int querySettleForCount(String idNo);

	/**
	 * 更新AC表复贷标识
	 * 
	 * @param loanId
	 */
	void updateComplexLoanStatus(String loanId);
	/**
	 * 区域负责人查询业绩（申请时间）
	 * @param channelCerformanceDto
	 * @return
	 */
	public List<Map<String, Object>> queryChannelPerformanceByRegionEmpAndApply(ChannelCerformanceDto channelCerformanceDto);
	/**
	 * 区域负责人查询业绩（自然时间）
	 * @param channelCerformanceDto
	 * @return
	 */
	public List<Map<String, Object>> queryChannelPerformanceByRegionEmpAndZiRan(ChannelCerformanceDto channelCerformanceDto);
	/**
	 * 区域负责人查询客户经理业绩（申请时间）
	 * @param channelCerformanceDto
	 * @return
	 */
	public List<Map<String, Object>> queryCustManagePerformanceByRegionEmpAndApply(ChannelCerformanceDto channelCerformanceDto);
	/**
	 * 区域负责人查询客户经理业绩（自然时间）
	 * @param channelCerformanceDto
	 * @return
	 */
	public List<Map<String, Object>> queryCustManagePerformanceByRegionEmpAndZiRan(ChannelCerformanceDto channelCerformanceDto);
	
	/**
	 * 
	 * @Title: updateApplyForMall   
	 * @Description:  将历史未完成的订单置为失效
	 * @param:      
	 * @return: int      
	 * @throws
	 */
	public int updateApplyForMall(String user_id);

	public List<Map<String, Object>> queryAllPerformanceByRegionEmpAndApply(ChannelCerformanceDto channelCerformanceDto);

	public List<Map<String, Object>> queryAllPerformanceByRegionEmpAndZiRan(ChannelCerformanceDto channelCerformanceDto);
	public void updateStatusByLoanId(String loanId);

	public Map<String, Object> selectAttributionByMobileSix(String mobile);
	
	/**
	 * 区域负责人搜索客户经理
	 * @param param
	 * @return
	 */
	List<Map<String,Object>> queryRegionEmployeeSeachEmployee(Map<String,Object> param);
	
	
	

	/**
	 * 黑名单验证
	 * @param identityCard  身份证号 (含有掩码)
	 * @return
	 */
	public int blackListVerifySpecial(@Param("identityCard1") String identityCard1,@Param("identityCard2") String identityCard2);
	
	
	
	
	/**
	 * 根据userId查询贷款信息
	 * @param userId
	 * @return
	 */
	public AcLoanApplyInfo queryApplyInfoByUserId(String userId);
	
	
	/**
	 * 获得所有可以预约的客户信息status=P01
	 * @param channelCerformanceDto
	 * @return
	 */
	public List<AcLoanApplyInfo> selectByStatus(String status);
     /**
      * 根据产品大类和期数获取产品小类及资金源列表
      * @param product_type 产品大类
      * @param tenor 分期数
      * @return
      */
	public List<Map<String, Object>> selectProductInfoList(@Param("product_type")String product_type, @Param("tenor")String tenor);
   
	/**
	 * 根据产品大类获取产品期数列表
	 * @param productType
	 * @return
	 */
	public List<Map<String, Object>> getTenorListByProductType(@Param("productType") String productType);
	/**
      * 根据产品小类获取获取相关利率（管理费和年利率）
      * @param productId
      * @return
      */
	public Map<String, Object> selectRateInfo(Long productId);

	//谁的方法没有提交,影响发布,补充个方法---曾祥松
	public List<AcLoanApplyInfo> selectByStatus(String string, String string2);
	
	//更新Cm_app_consumption
	public void updateCmApp (AcLoanApplyInfo acLoanApplyInfo);
	
	public List<AcLoanApplyInfo> selectByStatuses(String[] params);
	
	/**
	 * 客户经理填写回退原因
	 * @param map
	 */
	public void cancelLoanShenPi(Map<String, String> map);
	
	/**
	 * 根据loanId获取已经生成保单的金额
	 * @param loanId
	 * @return
	 */
	BigDecimal getBxAssureMoneyByLoanId(String loanId);
	/**
	 * 查询是否之前有黑名单标识
	 * @param identityCard
	 * @return
	 */
	public int findMobileBlackByIdCard(String identityCard);
	/**
	 * 拒绝状态
	 * @param identityCard
	 * @return
	 */
	public int findRefuseByIdCard(String identityCard);

	/**
	 * 根据手机号查询黑名单
	 * @param identityCard
	 * @return
	 */
	public int findMobileNumBlackByIdCard(String mobile);
	/**
	 * 返回省的拼音
	 * @param chinaStr
	 * @return
	 */
	public String getEnByChina(String chinaStr);

	/**
	 * 根据身份证来查询他在我们这边所有的单子的状态
	 * @param custIdCard
	 * @return
	 */
	public List<String> getStatusByIdCard(String custIdCard);
	
	List<Map> getCreditStatus(String loanId);
	void updateAcLoanCreditInvestigation(String loanId);
	
	void updateLoanCreditInvestigation(@Param("status") String status, @Param("loanId") String loanId);

	/**
	 * 卡牛所需要跑决策的数据
	 * @return
	 */
	public List<AcLoanApplyInfo> getNeedStrategyData();
	
	/**
	 * updateNoAdmittance 更新为不准入
	 * @param loanId
	 */
	void updateNoAdmittance(String loanId);
	/**
	 * 迁移客户至新负责人
	 * @param oldUserId
	 * @param newUserId
	 * @return
	 */
	public int moveCustToNewPrincipal(@Param("oldUserId") String oldUserId, @Param("newUserId") String newUserId);

	/**
	 * 查询主表信息，将地址类code转换为地址
	 * @param loanId
	 * @return
	 */
	public AcLoanApplyInfoAddress findAdressInfoByLoanId(@Param("loanId") String loanId);
	/**
	 * 
	* @Title: queryLoanByCondition 
	* @Description:查询贷款数据  
	* @param map
	* @return       
	* @author 李瑶
	* @date 2018年8月2日 下午5:22:26
	 */
	List<AcLoanApplyInfo> queryLoanByCondition(Map<String,Object> map);
	
	int findSesameIdentCount(String loanId);
	
	/**
	 * 
	* @Title: selectCustApplyingLoanList 
	* @Description:查询客户所有在途的进件  
	* @param idCardNo
	* @return       
	* @author 李瑶
	* @date 2018年8月22日 下午4:44:25
	 */
	List<AcLoanApplyInfo> selectCustApplyingLoanList(String idCardNo);

	/**
	 * 车险分期进件判断客户是否有未提交单子
	 * @param productType
	 * @param customerIdentityCard
	 * @return
	 */
	public Integer selectIsSubmitApplications(@Param("productType")Long productType, @Param("customerIdentityCard")String customerIdentityCard);
	/**
	 *分页查询贷款信息
	 * @param map
	 * @param pagebounds
	 * @return
	 */
	public List<AcLoanApplyInfo> queryLoanInfoByCondition(Map<String,Object> map, PageBounds pagebounds);
	
	/**
	 * 根据身份证去查询黑名单表，匹配到的记录取ID最小的记录的id<br>
	 * 用于比较是命中老的黑名单还是新的黑名单
	 * wanggang
	 * @param identityCard
	 * @return
	 */
	public Long getblackListIdByIdCard(@Param("identityCard") String identityCard);
	
	
	public Long getblackListIdByMobile(@Param("mobile")  String mobile);

	/**
	 * 通过证件号码查询所有结清的单
	 * 
	 * @param identityCardNo
	 * @return
	 */
	public List<Map<String, Object>> querySettleLoan(String identityCardNo);
	
	
	public List<loanSuccessDto> loanSuccessList();
	
	public int isPassRule(@Param("custIdCard") String custIdCard, @Param("days") Integer days);
	
	/**
	 * 獲取配置
	 * @param key
	 * @return
	 */
	public Map<String, String> getAppConfigByKey(@Param("key") String key);
	
	/**
	 * 查询嘉银现金分期 数据是否已存在
	 * liuqin
	 * @param refOrderId
	 * @return
	 */
	public int queryJiaYinJinKApplyLoanBasicInfo(@Param("refOrderId")String refOrderId);
	
	/**
	 * 修改成已放款状态
	 * @param merchantCode
	 * @param loanId
	 */
	public void updateJiaYinJinKApplyLoanResult(@Param("merchantCode")String merchantCode,@Param("loanId")String loanId);
	
	
}

